﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Dapper;
using LibMS.Models;

namespace LibMS.Controllers
{
    [Authorize]
    public class LibUserController : Controller
    {
        private readonly UnitOfWork _unitOfWork = new UnitOfWork();
        //
        // GET: /User/

        [Authorize(Roles = "System Admin")]
        public ActionResult GetDataForAdmin()
        {
            int? total;
            string message;
            var parameters = new DynamicParameters();
            parameters.Add("@PageSize", 10);
            parameters.Add("@PageIndex", 1);
            parameters.Add("@OrderBy", "UserName");
            var data = _unitOfWork.CmsUser.GetData(out total, out message, parameters);
            if (data == null)//Query error
            {
                ViewData["success"] = false;
                ViewData["message"] = message;
                return View("AdminListUser");
            }
            //Success
            var sqlResult = data as List<CmsUser> ?? null;
            ViewData["success"] = true;
            ViewData["total"] = total;
            return View("AdminListUser", sqlResult);
        }
    }
}
